import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
// 导入全局样式表
import './assets/css/global.css'
// 导入第三方图标
import './assets/fonts/iconfont.css'
// 导入树形图表插件
import TreeTable from 'vue-table-with-tree-grid'
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
// 导入 NProgress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import dayjs from 'dayjs' // 可以全局使用dayjs

import axios from 'axios'
Vue.prototype.dayjs = dayjs

// 配置请求的根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 在request拦截器中展示进度条
axios.interceptors.request.use(config => {
  NProgress.start()
  // console.log(config)
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
// 在response拦截器中结束进度条
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)

Vue.use(VueQuillEditor /* { default global options } */)

Vue.filter('dateFormat', function (cellValue) {
  // 格式化时间
  if (cellValue === undefined || cellValue === null) {
    return ''
  }
  return dayjs(cellValue).format('YYYY-MM-DD HH:mm')
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
